﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace ZJF.MultiThread
{
    internal class Program
    {
        static void Main(string[] args)
        {

            // 直接将一个函数传递给Thread构造方法
            // Thread t = new Thread(StartThread);
            // 将一个匿名函数传递给Thread
            //Thread t = new Thread(delegate ()
            //{
            //    Thread.Sleep(500);
            //    Console.WriteLine("我是子线程");
            //});
            // 将一个lambda表达式传递给Thread
            Thread t = new Thread(() =>
            {
                Thread.Sleep(500);
                Console.WriteLine("我是子线程");
            });

            t.IsBackground = true;  // 设置背景线程，主线程结束，背景线程也结束
            t.Start();


            Console.WriteLine("我是主线程");

            Console.ReadLine();
        }

        static void StartThread()
        {
            Thread.Sleep(1000);
            Console.WriteLine("我是子线程！");
        }
    }
}
